package com.custom.action.core.methods.others;

import com.custom.action.core.methods.AbstractMethod;
import com.custom.action.core.methods.MethodKind;
import com.custom.comm.utils.AssertUtil;
import com.custom.jdbc.interfaces.CustomSqlSession;
import com.custom.jdbc.interfaces.TransactionExecutor;
import com.custom.jdbc.session.DbTxLevel;
import com.custom.jdbc.session.JdbcSqlSessionFactory;

/**
 * @author XiaoBai
 * @since 2024/3/28 15:43
 * 事务方法-可添加隔离级别
 */
public class ExecTransLevel extends AbstractMethod {

    @Override
    protected <T> CustomSqlSession createSqlSession(JdbcSqlSessionFactory sqlSessionFactory, Class<T> target, Object[] params) throws Exception {
        return null;
    }

    @Override
    public <T> Object doExecute(JdbcSqlSessionFactory sqlSessionFactory, Class<T> target, Object[] params) throws Exception {
        AssertUtil.isTrue(params[0] != null);
        DbTxLevel level = (DbTxLevel) params[0];
        TransactionExecutor transactionExecutor = (TransactionExecutor) params[1];
        sqlSessionFactory.handleTransaction(level, transactionExecutor);
        return null;
    }

    @Override
    public MethodKind getKind() {
        return MethodKind.EXEC_TRANS_LEVEL;
    }
}
